package com.gxsyh.nantie.user.management.provider.service.impl;


import com.gxsyh.nantie.user.management.provider.domain.TbDepartment;
import com.gxsyh.nantie.user.management.provider.mapper.TbDepartmentMapper;
import com.gxsyh.nantie.user.management.provider.service.TbDepartmentService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @email yom535@outlook.com
 * @author: 刘锋嘉(Liu Fengjia)
 * @date: 2020/1/6
 * @time: 11:48
 * @Description:
 */
@Service
public class TbDepartmentServiceImpl implements TbDepartmentService {

    @Resource
    private TbDepartmentMapper tbDepartmentMapper;

    @Override
    public List<TbDepartment> queryingSubsetDepartmentsId(Long id) {
        Example example=new Example(TbDepartment.class);
        example.createCriteria().andEqualTo("parentId",id).andEqualTo("type",0);

        return tbDepartmentMapper.selectByExample(example);
    }

    @Override
    public int insterDepartment(Long id,Long mainDepartmentId, String addedDepartment,int type) {
        TbDepartment tbDepartment=new TbDepartment();
        tbDepartment.setId(id);
        tbDepartment.setName(addedDepartment);
        tbDepartment.setParentId(mainDepartmentId);
        tbDepartment.setCreatetime(new Date());
        tbDepartment.setType(type);
        return tbDepartmentMapper.insert(tbDepartment);
    }

    @Override
    public List<TbDepartment> selectSubsetDepartment(Long parentId) {
        return tbDepartmentMapper.selectSubsetDepartment(parentId);
    }

    @Override
    public List<TbDepartment> selectParentDepartment(Long parentId) {
        return tbDepartmentMapper.selectParentDepartment(parentId);
    }

    @Override
    public List<TbDepartment> queryingSubsetApartmentId(Long id) {
        Example example=new Example(TbDepartment.class);
        example.createCriteria().andEqualTo("parentId",id).andEqualTo("type",1);
        return tbDepartmentMapper.selectByExample(example);
    }
}

